package com.synchrodata.util;


import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
import org.apache.log4j.Logger;

public class PropertiesUtil {
 
    private static Logger logger =  Logger.getLogger(PropertiesUtil.class);
    private static Properties props;
 
    static {
        String fileName = "param.properties";
        props = new Properties();
        try {
        	//调用外部同目录下的配置文件 导出jar是使用
        	/*File file = new File(fileName);
       	    props.load( new FileInputStream(file));*/
        	
        	//读取src下的配置文件 (开发环境使用)
       	    props.load(new InputStreamReader(PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName),"UTF-8"));
        } catch (IOException e) {
            logger.error("配置文件读取异常",e);
        }
    }
    public static String getProperty(String key){
        String value= props.getProperty(key.trim());
        return value.trim();
    }
    
    public static int getPropertyInt(String key) {
		String value = props.getProperty(key.trim());
		return Integer.parseInt(value);
	}
 
}
